﻿using DotNetMVC.Website.Areas.WebAdmin.Common;
using DotNetMVC.Website.Areas.WebAdmin.Filters;
using DotNetMVC.Website.Areas.WebAdmin.Models.StaticPage;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace DotNetMVC.Website.Areas.WebAdmin.Controllers
{
    public class StaticPageController : Controller
    {
        // GET: WebAdmin/StaticPage
        [HttpGet]
        [AdminAuthorize(IsCheck = true)]
        public ActionResult Index()
        {
            //缓存key
            string key = Guid.NewGuid().ToString();
            StaticPageHelper.RebuildAll(ControllerContext,key);
            return Content("");
        }

        /// <summary>
        /// 生成进度
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult GetRebuildStaticPageProgress(string key)
        {
            string cacheKey = "StaticPage_" + key;
            //读取缓存
            CreatProgress model = (CreatProgress)HttpContext.Cache[cacheKey];
            //RebuildStaticPageResult model = Website.Common.MemcacheMgr.Instance.GetValue<RebuildStaticPageResult>(cacheName);
            if (model == null)
            {
                return Json(new CreatProgress { TotleCount = 0, RebuildCount = 0, Percent = "0%" });
            }
            return Json(new CreatProgress { TotleCount = model.TotleCount, RebuildCount = model.RebuildCount, Percent = model.Percent });
        }
    }
}